package com.hxd.mall.module.usercenter.fragment

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.hxd.mall.module.product.home.HomeTypeFragment
import com.hxd.mall.module.product.home.bean.Data
import com.hxd.mall.module.product.home.bean.Resource

/**
 * Create by yinzhengwei on 2019-11-05
 * @Function
 */
class FragmentAdapter(fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {

    var status = arrayOf("ALL", "UNSETTLED", "SETTLED", "CANCELED")

    override fun getItem(position: Int): Fragment {
        return PageFragment(status[position], position)
    }

    override fun getCount() = 4
}

class FunsFragmentAdapter(fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {

    override fun getItem(position: Int): Fragment {
        return FunsPageFragment()
    }

    override fun getCount() = 1
}

class HomeTypeFragmentAdapter(fragmentManager: FragmentManager, var data: Data?) : FragmentStatePagerAdapter(fragmentManager) {

    override fun getItem(position: Int): Fragment {
        var navigationUrl = ""
        var titleStr = ""

        data?.navigationLayout?.resources?.run {
            navigationUrl = this[position].entryUri ?: ""
            titleStr = this[position].title ?: ""
        }
        return HomeTypeFragment(position, titleStr, navigationUrl)
    }

    override fun getCount() = data?.navigationLayout?.resources?.size ?: 0
}